from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
from reportlab.lib.pagesizes import A4, letter, landscape, portrait
PAGE_HEIGHT=defaultPageSize[1]; PAGE_WIDTH=defaultPageSize[0]
styles = getSampleStyleSheet()


#precalculate some basics
top_margin = A4[1] - inch
bottom_margin = inch
left_margin = inch
right_margin = A4[0] - inch
frame_width = right_margin - left_margin


title = """
User Report
Your Web Publishers
EriKin Corporation
December 11, 2006
"""
pageinfo = "platypus example"
webname = "www.erikin.com"

    
def TitlePage(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Italic',12)

    # header
    canvas.drawString(left_margin, top_margin + 2, "User Report - " + webname)
    canvas.line(left_margin, top_margin, right_margin, top_margin)

    # body
    canvas.setFont('Times-Bold',16)
    tx = canvas.beginText(PAGE_WIDTH/2.0, 3 * inch)
    tx.textLines(title, trim=1)
    canvas.drawText(tx)

    # footer
    canvas.line(left_margin, bottom_margin, right_margin, bottom_margin)
    canvas.drawCentredString(0.5*A4[0], 0.5 * inch,
               "Page %d" % canvas.getPageNumber())
    canvas.restoreState()

def myLaterPages(canvas, doc):
    canvas.saveState()
    canvas.line(left_margin, bottom_margin, right_margin, bottom_margin)
    canvas.drawCentredString(0.5*A4[0], 0.5 * inch,
               "Page %d" % canvas.getPageNumber())
    canvas.restoreState()


def go():
    doc = SimpleDocTemplate("phello.pdf")

    Story = [Spacer(1,2*inch)]
    style = styles["Normal"]
    for i in range(100):
        # bogustext = ("This is Paragraph number %s. " % i) *20
        t = "www.unt.edu:\n\nUser\t\tUid\ntest user\t\ttuser\n"
        bogustext = (t)
        p = Paragraph(bogustext, style)
        Story.append(p)
        Story.append(Spacer(1,0.2*inch))
    doc.build(Story, onFirstPage=_doNothing, onLaterPages=myLaterPages)

go()
